Clang Format
A C++ code formatter based on Clang Format, for beautiful code with minimal effort in Sublime Text 3
Details
Installs
- Total 55K
- Win 21K
- Mac 13K
- Linux 21K
Nov 7 | Nov 6 | Nov 5 | Nov 4 | Nov 3 | Nov 2 | Nov 1 | Oct 31 | Oct 30 | Oct 29 | Oct 28 | Oct 27 | Oct 26 | Oct 25 | Oct 24 | Oct 23 | Oct 22 | Oct 21 | Oct 20 | Oct 19 | Oct 18 | Oct 17 | Oct 16 | Oct 15 | Oct 14 | Oct 13 | Oct 12 | Oct 11 | Oct 10 | Oct 9 | Oct 8 | Oct 7 | Oct 6 | Oct 5 | Oct 4 | Oct 3 | Oct 2 | Oct 1 | Sep 30 | Sep 29 | Sep 28 | Sep 27 | Sep 26 | Sep 25 | Sep 24 | Sep 23 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Windows | 2 | 3 | 6 | 4 | 0 | 2 | 8 | 3 | 4 | 3 | 5 | 4 | 7 | 5 | 4 | 6 | 10 | 8 | 6 | 4 | 6 | 8 | 8 | 4 | 1 | 1 | 6 | 1 | 0 | 1 | 2 | 4 | 4 | 4 | 4 | 3 | 3 | 3 | 4 | 1 | 4 | 4 | 7 | 2 | 3 | 7 |
Mac | 0 | 2 | 2 | 1 | 0 | 2 | 3 | 1 | 3 | 2 | 1 | 4 | 1 | 2 | 2 | 1 | 1 | 0 | 3 | 0 | 4 | 1 | 0 | 1 | 2 | 4 | 2 | 4 | 0 | 0 | 5 | 3 | 0 | 1 | 0 | 3 | 1 | 1 | 2 | 0 | 0 | 1 | 3 | 5 | 0 | 3 |
Linux | 3 | 5 | 3 | 0 | 4 | 4 | 3 | 1 | 3 | 5 | 4 | 5 | 5 | 7 | 2 | 2 | 5 | 2 | 0 | 0 | 4 | 6 | 1 | 8 | 4 | 2 | 4 | 2 | 3 | 3 | 6 | 2 | 4 | 0 | 2 | 5 | 5 | 2 | 8 | 3 | 1 | 1 | 3 | 6 | 5 | 5 |
Readme
- Source
- raw.githubusercontent.com
Clang Format
What it does
Clang-format is a tool for formatting C++, built on LLVM. This is a package that allows you to run it easily from within Sublime Text.
About
In this package, we provide an alternative wrapper around clang-format for use within Sublime Text 3. Whilst LLVM does provide a very simple plugin to work with Sublime Text here, it doesn't really exploit any of the Sublime Text package functionality. We add new features such as customising the style from a settings file, selecting styles using the Command Palette, and easier installation.
Installing
- Install
clang-format
in one of the following ways:- Install using your package manager, e.g.
sudo apt-get install clang-format
orsudo apt-get install clang-format-5.0
. - Download the entire LLVM toolchain
and extract the
clang-format
binary. Just extract the.tar.xz
file and copybin/clang-format
into your PATH (e.g./usr/local/bin
).
- Install using your package manager, e.g.
- Install this package through Package Control in the usual way.
- Set the path to the clang-format binaries. You can do this from within Sublime
Text by choosing
Clang Format - Set Path
from the command palette. Hint: the path should look something like this[path/to/clang]/clang/bin/clang-format
. If clang-format is in your system path, you shouldn't need to do anything.
Use
- Default shortcut is
super+option+a
on OSX andoption+cmd+a
otherwise. This will apply clang-format to the selection. - From the command palette, you can select the formatting type by using
Clang Format: Select Style
. You will find the small number of defaults, and also a new 'Custom' entry. Selecting this entry allows you to customise the style through a settings file. You can access it from the main menu, underPackage Settings
. In this file you can add custom rules, such asAllmen
style braces, and different indents. For examples see http://clang.llvm.org/docs/ClangFormatStyleOptions.html. - Settings for the 'Custom' format and others are available through the Sublime Text preferences.
- It is possible to run the formatter on every save to a file, change settings
to
"format_on_save": true
. - To run the formatter in one stroke, press
ctrl+e
for windows and linux orsuper+e
for OSX. You can always change the keybinding in the keymap to your liking. - To change settings on a per-package basis, add them under
ClangFormat
key, example project.sublime-settings:
{
"folders": [],
"settings": {
"ClangFormat": {
"format_on_save": true
}
}
}
If You Liked This
… And want to contribute, PR's gladly accepted!
Maybe you'll like my other plugin, iOpener. It lets you open files by path, with completion, history, and other goodies.
Otherwise, why not pop on over and star this repo on GitHub?
Credits
Thanks to the LLVM project for doing the hard work, including writing clang format, and also the original Sublime Text plugin on which this package is based.
Also thanks to y0ssar1an, Bendtherules and other contributors for their improvements!
Finally
Why not go and watch the video that got me interested in clang-format in the first place?